/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package labbd_._projetofinal;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.oracore.OracleType;

/**
 *
 * @author bimaoe
 */
public class Empresa {

	private BigDecimal cnpj;
	private String nome;

	public Empresa(BigDecimal cnpj, String nome) {
		this.cnpj = cnpj;
		this.nome = nome;
	}

	public BigDecimal getCnpj() {
		return cnpj;
	}

	public String getNome() {
		return nome;
	}

	public static ArrayList <Empresa> getEmpresas (OracleConnection in_conn) throws SQLException {
		ArrayList<Empresa> ret = new ArrayList<Empresa>();
		String query = "begin pkg_empresa.proc_getEmpresas(?); end;";
		OracleCallableStatement Ocallstmt = (OracleCallableStatement) in_conn.prepareCall(query);
		Ocallstmt.registerOutParameter(1, OracleTypes.CURSOR);
		Ocallstmt.execute();
		ResultSet rs = (ResultSet) Ocallstmt.getObject(1);
		while (rs.next()) {
			ret.add (new Empresa (rs.getBigDecimal("CNPJ"), rs.getString("NOME")));
		}
		return ret;
	}

}
